<template>
	<view class="page">
		<Header title="车队列表" />
		<view class="" style="height: 150rpx;"></view>
		<!-- 我的车辆 -->
		<view class="carList">
			<view class="carItem" v-for="(item,i) in mood" >
				<view class="ItemMain" @click="editCarInfo(item)">
					<view class="ItemLeft">
						<view class="carNumber">
							{{item.numberplate}}
						</view>
						<view class="carType">
							<span style="margin-left: 16rpx;">{{item.brandModel}}</span>
						</view>
						<view v-if="item.certStatus==2" class="trueBtn">
							已认证
						</view>
						<view v-else class="trueBtn red">
							认证中
						</view>
					</view>
					<image class="carPic" src="@/static/pic/xiaomian.png" mode=""></image>
				</view>
				<view class="ItemBottom">
					<view class="radioBox" @click="qiehuan(i,item)">
						<view class="radio">
							<image v-if="item.isUse==1"  class="gou" src="@/static/pic/gou.png" mode="widthFix"></image>
						</view>
						<view class="radioLabel">
							默认车辆
						</view>
					</view>
					<view class="delete">
						<!-- 删除 -->
					</view>
				</view>
			</view>
		</view>
		<view class="addBtn" @click="addCar" v-if="mood.length<2">
			添加车辆
		</view>
	</view>
</template>

<script>
	import order from '@/api/modules/order.js'
	import driver from '@/api/modules/driver.js'
	import Header from '@/components/header/header.vue'
	export default {
		components: {
			Header
		},
		data() {
			return {
				mood: [],
				result: {},
			}
		},
		onLoad() {
			this.cread()
		},
		methods: {
			editCarInfo(e) {
				uni.navigateTo({
					url: '/subPackages/driver/addCar/addCar?vehicleId=' + e.vehicleId+'&certStatus='+e.certStatus
				});
			},
			qiehuan(e, i) {
				if (this.mood[e].isUse === 0) {
					driver.modifyDriverVehicleInfoByVid({
						vehicleId: i.dvid
					}).then((res) => {
						if (res.data.code == 200) {
							this.mood[e].isUse = 1
							if (e == 0) {
								this.mood[1].isUse = 0
							} else {
								this.mood[0].isUse = 0
							}
							uni.showToast({
								title: "操作成功",
								icon: "none"
							})
						} else {
							uni.showToast({
								title: "操作失败",
								icon: "none"
							})
						}
					})
				}
			},
			async cread() {
				let res = await this.$http.driver.driverList();
				this.mood = res.data.data;
			
				order.queryDriverStateDetail({}).then((res) => {
					if (res.data.code == 200) {
						this.result = res.data.data;
					}
				});
			},
			addCar() {
				if (this.result) {
					if (this.result.cert_status == 2) {
						uni.navigateTo({
							url: '/subPackages/driver/addCar/addCar'
						})
					} else {
						uni.showToast({
							title: "司机未认证",
							icon: "none"
						})
					}
				}

			},
			goBack() {
				uni.switchTab({
					url: '/pages/my/my'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		height: 100vh;
		background-color: #F3F3F3;
	}
	.addBtn{
		
		position: fixed;
		bottom: 55rpx;
		left:30rpx;
		width: 690rpx;
		height: 110rpx;
		background: #29B0FD;
		border-radius: 10rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		text-align: center;
		line-height: 110rpx;
		color: #FFFFFF;
		
	}
	.carList{
		width: 100%;
		height:calc(100vh - 270rpx);
		// background-color: red;
		overflow: scroll;
		padding: 30rpx;
		box-sizing: border-box;
		.carItem{
			width: 690rpx;
			height: 352rpx;
			box-sizing: border-box;
			margin-bottom: 25rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			.ItemBottom{
				height:94rpx;
				width: 100%;
				box-sizing: border-box;
				padding: 0 46rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.radioBox{
					height:100%;
					display: flex;
					align-items: center;
					.radio{
						
						width: 32rpx;
						height: 32rpx;
						background: #FFFFFF;
						border: 2px solid #959595;
						border-radius: 50%;
						margin-right: 18rpx;
						position: relative;
						.gou{
							position: absolute;
							width: 38rpx;
							height: 38rpx;
							left:50%;
							top:50%;
							transform: translate(-50%,-50%);
						}
					}
					
					.radioLabel{
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #262626;
					}
				}
				.delete{
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #262626;
				}
			}
			
			.ItemMain{
				padding: 65rpx 0 43rpx;
				margin:0 46rpx;
				border-bottom:1rpx solid #F0EFEF;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				.ItemLeft{
					.carNumber{
						font-size: 40rpx;
						font-family: PingFang SC;
						font-weight: 600;
						color: #262626;
						margin-bottom: 4rpx;
					}
					.carType{
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #999999;
						margin-bottom: 20rpx;
					}
					.trueBtn{
						text-align: center;
						line-height: 42rpx;
						width: 98rpx;
						height: 42rpx;
						background: #FFFFFF;
						border: 1px solid #0094E9;
						border-radius: 4rpx;
						font-size: 24rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #0094E9;
						&.red{
							color:#EA4F4C;
							border-color:#EA4F4C;
						}
					}
				}
			}
			
			.carPic{
				width: 241.8rpx;
				height:125.8rpx;
			}
		}
	}
</style>
